//
//  SEGTalkSquareViewModel.m
//  Commom
//
//  Created by 梁学彰 on 2020/6/8.
//

#import "SEGTalkSquareViewModel.h"

@implementation SEGTalkSquareViewModel
#pragma mark - life cycle
- (instancetype)init {
    if (self = [super init]) {
        _page = 1;
    }
    return self;
}

#pragma mark - init

#pragma mark - send request
- (RACSignal *)segRequestByHandData {
    @weakify(self);
    RACSignal *signal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        @strongify(self);
        
        [self.topicDeteailManager  requestTalkHotTopicWithPageNo:self.page Finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
            if(!isSuccessed){
                [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:errorMessage}]];
            }
            [subscriber sendCompleted];
        }];
        
        return nil;
    }];
    return signal;
}

- (RACSignal *)segRequestData {
    @weakify(self);
    RACSignal *signal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        @strongify(self);
        
        [self.topicDeteailManager requestTalkFinished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
            if(!isSuccessed){
                [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:errorMessage}]];
            }
            [subscriber sendCompleted];
           // [self.tableView stopAnimatingWindmill];
        }];
        
        return nil;
    }];
    return signal;
}

#pragma mark - custom delegate

#pragma mark - system delegate

#pragma mark - event response

#pragma mark - private methods

#pragma mark - setter and getter
- (SEGNewTopicManager *)topicDeteailManager {
    if (!_topicDeteailManager) {
        _topicDeteailManager = [SEGNewTopicManager new];
    }
    return _topicDeteailManager;
}
@end
